package com.macro.mall.service.impl;

import cn.hutool.core.date.DateTime;
import com.aliyun.oss.ServiceException;
import com.github.pagehelper.PageHelper;
import com.macro.mall.dto.BmsSightseeingBusParam;
import com.macro.mall.dto.BmsSightseeingBusPicParam;
import com.macro.mall.dto.BmsSightseeingBusPointParam;
import com.macro.mall.mapper.BmsSightseeingBusMapper;
import com.macro.mall.mapper.BmsSightseeingBusPicMapper;
import com.macro.mall.mapper.BmsSightseeingBusPointMapper;
import com.macro.mall.model.*;
import com.macro.mall.service.BmsSightseeingBusPointService;
import com.macro.mall.service.BmsSightseeingBusService;
import com.macro.mall.utils.UserUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Random;


/**
 * 观光车点位Service实现类
 * Created by macro on 2018/4/26.
 */
@Service
public class BmsSightseeingBusPointServiceImpl implements BmsSightseeingBusPointService {
    @Autowired
    private BmsSightseeingBusPointMapper bmsSightseeingBusPointMapper;
    @Autowired
    private UserUtils userUtils;


    /**
     * 分页查询观光车
     * @return
     */
    @Transactional
    @Override
    public List<BmsSightseeingBusPoint> getList(BmsSightseeingBusPointParam bmsSightseeingBusPointParam) {
        PageHelper.startPage(bmsSightseeingBusPointParam.getPageNum(), bmsSightseeingBusPointParam.getPageSize());;
        BmsSightseeingBusPoint bmsSightseeingBusPoint = new BmsSightseeingBusPoint();
        BeanUtils.copyProperties(bmsSightseeingBusPointParam, bmsSightseeingBusPoint);
        List<BmsSightseeingBusPoint> list = bmsSightseeingBusPointMapper.selectAll(bmsSightseeingBusPoint);
        return list;
    }

    /**
     * 新增观光车
     * @param
     * @return
     */
    @Transactional
    @Override
    public int create(BmsSightseeingBusPointParam bmsSightseeingBusPointParam) {
        //获取当前登录用户id
        BmsSightseeingBusPoint bmsSightseeingBusPoint = new BmsSightseeingBusPoint();
        BeanUtils.copyProperties(bmsSightseeingBusPointParam, bmsSightseeingBusPoint);
        return bmsSightseeingBusPointMapper.insert(bmsSightseeingBusPoint);
    }

    /**
     * 更新观光车
     * @param
     * @return
     */
    @Transactional
    @Override
    public int update(BmsSightseeingBusPointParam bmsSightseeingBusPointParam) {
        //根据传过来的id 进行逻辑删除 isDelete更新成1
        BmsSightseeingBusPoint bmsSightseeingBusPoint = new BmsSightseeingBusPoint();
        BeanUtils.copyProperties(bmsSightseeingBusPointParam, bmsSightseeingBusPoint);
        return bmsSightseeingBusPointMapper.updateByPrimaryKey(bmsSightseeingBusPoint);
    }


    /**
     * 获取单个观光车点位信息
     * @param id
     * @return
     */
    @Override
    public BmsSightseeingBusPoint getItem(Long id) {
        return bmsSightseeingBusPointMapper.selectByPrimaryKey(id);
    }

    /**
     * 删除观光车点位
     * @param ids
     * @return
     * 完成
     */
    @Transactional
    @Override
    public int delete(List<Long> ids) {
        //删除点位表根据id去把isdelete更新成1
        return bmsSightseeingBusPointMapper.updateByNew(ids);

    }

}
